package com.chatSystem;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;

public class ServerWindow {
    JTextArea jTextArea;
    public static JButton xuan = new JButton("xuan");
    public static JButton tao = new JButton("tao");
    public static JButton yuan = new JButton("yuan");
    ServerReadAndPrint.serverWindowListen listener;


    //向文本区域添加信息
    void setTextArea(String str){
        jTextArea.append(str + '\n');
        jTextArea.setCaretPosition(jTextArea.getDocument().getLength());//设置滚动条在下侧
    }
    public static JButton getXuan(){
        return xuan;
    }
    public static JButton getTao(){
        return tao;
    }
    public static JButton getYuan(){
        return yuan;
    }


    //与外部连接的接口,用来调用服务器窗体
    public ServerWindow(){
        JFrame jFrame =  new JFrame("服务器端");
        JPanel jPanel = new JPanel();
        JPanel logOut = new JPanel();

        //设置外框
        jFrame.setBounds(200,100,350,450);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //设置内部组件
        JLabel label = new JLabel("==您已登录聊天器(服务器端)==");
        jPanel.add(label);

        jTextArea = new JTextArea(20,30);
        jTextArea.setEnabled(false);
        JScrollPane scroll = new JScrollPane(jTextArea);//将滚动条放入文本框
        scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);//垂直滚动条
        jPanel.add(scroll);
        jFrame.add(jPanel, BorderLayout.NORTH);
        jFrame.setResizable(false);
        jFrame.setVisible(true);


        JLabel logOutLabel = new JLabel("下线用户");
        logOut.add(logOutLabel);
        xuan.setEnabled(false);
        tao.setEnabled(false);
        yuan.setEnabled(false);
        logOut.add(xuan);
        logOut.add(tao);
        logOut.add(yuan);
        jFrame.add(logOut,BorderLayout.SOUTH);
        listener = new ServerReadAndPrint().new serverWindowListen();
        xuan.addActionListener(listener);
        tao.addActionListener(listener);
        yuan.addActionListener(listener);


        jFrame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e){
                System.exit(0);
            }
        });

    }

}
